<?php
/**
 * @package : GearmandJob.
 * @class-name : GearmandWriteJob()
 * @author : stephen.mo <stephen.mo@achievo.com>
 * @date : 2010-04-08
 */
require_once 'TVB/Config/requires.php';
require_once 'TVB/GearmandJob/lib/publicGearmandConfig.class.php';
require_once 'TVB/GearmandJob/lib/createObjectOfClientJob.class.php';

class GearmandWriteJob {
    static public function write($log_entitys) {
        //$log_entitys = json_decode($log_entity,true);

        $action = (!isset($log_entitys['action']) || $log_entitys['action']==1 || empty($log_entitys['action'])) ? 'addTask' : 'do';
        $level = (!isset($log_entitys['level']) || strtoupper($log_entitys['level'])=='H' || empty($log_entitys['level']) ) ? 'High' : ((strtoupper($log_entitys['level'])=='L') ? 'Low' : 'Normal');
        $style = (!isset($log_entitys['style']) || strtoupper($log_entitys['style'])=='B' || empty($log_entitys['style'])) ? 'Background' : '';

        //intergration the function name when you need to run or debug it.
        $function = $action.$level.$style;
       
        //write the queue to Job-Servers.
        $gmclient = createObjectOfClientJob::getInstance();
        $result = $gmclient->{$function}('mstatWirteJobFromJobServers',$log_entitys['data']);
        if ($action!='do') {
            $result = $gmclient->runTasks();
        }

        //return the result;
        return $result;
    }
}

?>
